package com.javastudy.jdkfeature.jdk5.formatter;

import java.util.Calendar;
import java.util.Formatter;

public class FormatTester {

    public static void main(String[] args) {
        String format = "%f";
        format = "%.2f";
        format = "%6.2f";
        format = "%1$.2f";
        StringBuilder stringBuilder = new StringBuilder();
        Formatter formatter = new Formatter(stringBuilder);
        formatter.format("Pi is approximately " + format +
                ", and e is about " + format, Math.PI, Math.E);
        System.out.println(stringBuilder);
//    String filename = args[0];
//
//    try {
//      File file = new File(filename);
//      FileReader fileReader = new FileReader(file);
//      BufferedReader reader = new BufferedReader(fileReader);
//
//      String line;
//      int i = 1;
//      while ((line = reader.readLine()) != null) {
//        System.out.printf("Line %d: %s%n", i++, line);
//      }
//
//    } catch (Exception e) {
//      System.err.printf("Unable to open file named '%s': %s",
//                        filename, e.getMessage());
//    }
        formatTime();
    }

    private static void formatTime() {
        System.out.printf("Right now it is %tr on " +
                        "%<tA, %<tB %<te, %<tY.%n",
                Calendar.getInstance());
        Calendar c = Calendar.getInstance();
        String s = String.format("Duke's Birthday: %1$tm %1$te,%1$tY", c);
        System.out.println(s);
    }
}